package org.dromara.system.api.services;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.AssertUtils;
import org.dromara.system.api.domain.vo.RemoteTenantVo;
import org.dromara.system.api.feign.SystemTenantClient;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: zhou shuai
 * @date: 2024/10/6 16:09
 * @version: v1
 */
@Slf4j
@Service("systemTenantApiService")
@RequiredArgsConstructor
public class SystemTenantApiService {

    private final SystemTenantClient systemTenantClient;

    /**
     * 根据租户id获取租户详情
     *
     * @author: zhou shuai
     * @date: 2024/10/6 16:10
     * @param: tenantId
     * @return: org.dromara.system.api.domain.vo.RemoteTenantVo
     */
    public RemoteTenantVo queryByTenantId(String tenantId) {
        R<RemoteTenantVo> tenantResult = systemTenantClient.queryByTenantId(tenantId);
        AssertUtils.assertTrue(R.isSuccess(tenantResult), "获取租户详情失败");
        return tenantResult.getData();
    }

    /**
     * 获取租户列表
     *
     * @author: zhou shuai
     * @date: 2024/10/6 16:11
     * @return: org.dromara.common.core.domain.R<java.util.List < org.dromara.system.api.domain.vo.RemoteTenantVo>>
     */
    public List<RemoteTenantVo> queryTenantList() {
        R<List<RemoteTenantVo>> tenantListResult = systemTenantClient.queryTenantList();
        AssertUtils.assertTrue(R.isSuccess(tenantListResult), "获取租户列表失败");
        return tenantListResult.getData();
    }

}
